<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>居中显示</title>
    <style>
        .f{
            width: 300px;
            height: 100px;
            background-color: lightseagreen;
            /* 水平位置居中 */
            /* margin: 25px auto; */

            /* 设置绝对定位，会破坏margin:auto的效果 */
            position: absolute;
            left: 50%;
            top: 50%;
            margin-top: -50px;
            margin-left: -150px;
        }

        .s{
            width: 30px;
            height: 30px;
            background-color: lightcoral;
            border-radius: 50%;

            /* 右顶角 */
            position: absolute;
            top:-5px;
            right: -5px;

            /* 文本水平居中 */
            text-align: center;
            /* 文本竖直居中 */
            line-height: 30px;
        }
    </style>
</head>
<body>
    <div class="f">
        <div class="s">X</div>
    </div>
</body>
</html>